package master

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)

type Config struct {
	ApiPort         int      `json:"apiPort"`
	ApiReadTimeout  int      `json:"apiReadTimeout"`
	ApiWriteTimeout int      `json:"apiWriteTimeout"`
	EtcdEndPoints   []string `json:"etcdEndpoint"`
	EtcdDialTimeout int      `json:"etcdDialTimeout"`
}

var (
	G_config *Config
)

func InitConfig(fileName string) (err error) {
	bytes, err := ioutil.ReadFile(fileName)
	if err != nil {
		return err
	}

	config := &Config{}
	err = json.Unmarshal(bytes, config)
	if err != nil {
		return err
	}

	G_config = config
	fmt.Println(config)

	return nil
}
